import { ref } from "vue"
function useViewModel() {
	
	//删除数据之后，返回页面的步长
	let delta = ref<number>(2)

	//时间选择器最早的时间
	let minDate = () : number => {
		const now = new Date();
		const year = now.getFullYear() - 10;
		const month = now.getMonth();
		const day = now.getDate();
		const dateTenYearsAgo = +new Date(year, month, day);
		return dateTenYearsAgo;
	}
	let maxDate = () : number => {
		const now = new Date();
		const year = now.getFullYear() + 10;
		const month = now.getMonth();
		const day = now.getDate();
		const dateTenYearsLater = +new Date(year, month, day);
		return dateTenYearsLater;
	}

	//时间选择器开关
	let firstContactDate_visible = ref<boolean>(false)
	//打开时间选择器
	let showFirstContactDate = () : void => {
		firstContactDate_visible.value = true
	}
	//时间选择器-确认
	let firstContactDate_confirm = (e : any) : string => {
		let { value } = e
		firstContactDate_visible.value = false
		return value
	}
	

	//表单校验
	const rules = {
		projectName: [
			{
				required: true,
				message: '请输入项目名称',
				trigger: ['blur', 'change'],
			},
		],
		enterpriseId: [
			{
				required: true,
				message: '请选择客户',
				trigger: ['blur', 'change'],
			},
		],
		contactName: [
			{
				required: true,
				message: '请输入联系人姓名',
				trigger: ['blur', 'change'],
			},
		],
		contactTitle: [
			{
				required: true,
				message: '请输入联系人职务',
				trigger: ['blur', 'change'],
			},
		],
		contactInformation: [
			{
				required: true,
				message: '请输入联系方式',
				trigger: ['blur', 'change'],
			},
		],
		firstContactDate: [
			{
				required: true,
				message: '请选择首次接触日期',
				trigger: ['blur', 'change'],
			},
		],
		deptId: [
			{
				required: true,
				message: '请选择对接公司',
				trigger: ['blur', 'change'],
			}
		],
		chargeName: [
			{
				required: true,
				message: '请选择负责人',
				trigger: ['blur', 'change'],
			},
		],
		teamInfo: [
			{
				required: true,
				message: '请选择团队成员',
				trigger: ['blur', 'change'],
			},
		],
	};


	return {
		minDate,
		maxDate,
		rules,
		firstContactDate_visible,
		firstContactDate_confirm,
		showFirstContactDate,
		delta
	}
}

export default useViewModel